package com.utils;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.crmeb.core.config.MybatisPlusConfig;
import com.crmeb.core.utils.RedisUtil;
import com.crmeb.core.utils.TableNameUtil;
import com.zbkj.crmeb.agent.service.AgentService;
import com.zbkj.crmeb.chant.service.ChannelDiscountService;
import com.zbkj.crmeb.chant.service.ICategoryMatchService;
import com.zbkj.crmeb.chant.service.IChannelMerchantService;
import com.zbkj.crmeb.express.service.FirstLogisticsCostService;
import com.zbkj.crmeb.express.service.ShippingTemplatesFreeService;
import com.zbkj.crmeb.express.service.ShippingTemplatesService;
import com.zbkj.crmeb.member.service.IMerchantMemberBenefitsService;
import com.zbkj.crmeb.member.service.IStoreProductDiscountService;
import com.zbkj.crmeb.store.dao.StoreProductDao;
import com.zbkj.crmeb.store.dao.StoreProductMerDao;
import com.zbkj.crmeb.store.dao.StoreProductValueMerDao;
import com.zbkj.crmeb.store.model.StoreProductMer;
import com.zbkj.crmeb.store.model.StoreProductValueMer;
import com.zbkj.crmeb.store.service.*;
import com.zbkj.crmeb.tools.service.MoneyExchangeService;
import com.zbkj.crmeb.user.service.UserMemberRecordService;
import com.zbkj.crmeb.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * 商户商品工具类
 * @author muyu.myw
 * @date 2020/9/28 11:46
 */
@Service
@Slf4j
public class StoreProductMerUtil {

    @Autowired
    StoreProductValueMerService storeProductValueMerService;
    @Autowired
    AgentService agentService;

    @Autowired
    StoreProductMerService storeProductMerService;

//    //商户商品表字段添加
//    public Boolean makeColumns(StoreProductMerDao storeProductMerDao, StoreProductValueMerDao storeProductValueMerDao, Integer merId) {
//
//        try {
//
//            //判断快递模板
//            String productTableName = "eb_store_product_mer_"+merId.toString()+"_mp";
//            String valueTableName = "eb_store_product_value_mer_"+merId.toString()+"_mp";
//
//            List<Integer> shippingTempList = storeProductMerDao.selectShippingTempId(productTableName);
//            if(shippingTempList.get(0)==0){
//                storeProductMerDao.addShippingTempId(productTableName);
//            }
//
//            List<Integer> valueList = storeProductValueMerDao.selectVolume(valueTableName);
//            if(valueList.get(0)==0){
//                storeProductValueMerDao.addVolume(valueTableName);
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//
//        }
//
//        return true;
//
//    }

    //商户商品表字段添加
    public Boolean makeColumnsTwo(Integer merId) {

        try {

            MybatisPlusConfig.tableNameMp.set(TableNameUtil.getProductMerName(merId));

            List<Integer> shippingTempList = storeProductMerService.selectShippingTempId(TableNameUtil.getProductMerName(merId));
            if(shippingTempList.get(0)==0){
                storeProductMerService.addShippingTempId(TableNameUtil.getProductMerName(merId));
                log.info("商户商品表处理结束:{}  ", TableNameUtil.getProductMerName(merId));
            }

            MybatisPlusConfig.productValueNameMp.set(TableNameUtil.getProductValueMerName(merId));

            List<Integer> valueList = storeProductValueMerService.selectVolume(TableNameUtil.getProductValueMerName(merId));
            if(valueList.get(0)==0){
                storeProductValueMerService.addVolume(TableNameUtil.getProductValueMerName(merId));
                log.info("商户商品明细表处理结束:{}  ", TableNameUtil.getProductValueMerName(merId));
            }

        } catch (Exception e) {
            e.printStackTrace();

        }

        return true;

    }
}